package com.umeng.analytics.game;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences;
import android.text.TextUtils;

import com.umeng.analytics.MobclickAgent;
import com.umeng.analytics.b;
import com.umeng.analytics.pro.ba;
import com.umeng.analytics.pro.bx;
import com.umeng.analytics.pro.by;
import com.umeng.analytics.pro.bz;
import com.umeng.analytics.pro.cb;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;

class c implements bx {
    private b a;
    private com.umeng.analytics.game.b b;
    private final int c;
    private final int d;
    private final int e;
    private final int f;
    private final int g;
    private final String h;
    private final String i;
    private final String j;
    private final String k;
    private final String l;
    private final String m;
    private final String n;
    private final String o;
    private final String p;
    private final String q;
    private final String r;
    private final String s;
    private final String t;
    private final String u;
    private final String v;
    private final String w;
    private final String x;
    private final String y;
    private Context z;

    public c() {
        this.a = MobclickAgent.getAgent();
        this.b = null;
        this.c = 100;
        this.d = 1;
        this.e = 0;
        this.f = -1;
        this.g = 1;
        this.h = "level";
        this.i = "pay";
        this.j = "buy";
        this.k = "use";
        this.l = "bonus";
        this.m = "item";
        this.n = "cash";
        this.o = "coin";
        this.p = "source";
        this.q = "amount";
        this.r = "user_level";
        this.s = "bonus_source";
        this.t = "level";
        this.u = "status";
        this.v = "duration";
        this.w = "curtype";
        this.x = "orderid";
        this.y = "UMGameAgent.init(Context) should be called before any game api";
        com.umeng.analytics.game.a.a = true;
    }

    void a(double arg6, int arg8) {
        if (this.z == null) {
            by.e("UMGameAgent.init(Context) should be called before any game api");
        } else {
            HashMap v0 = new HashMap();
            v0.put("coin", Long.valueOf(((long) (100 * arg6))));
            v0.put("bonus_source", Integer.valueOf(arg8));
            if (this.b.b != null) {
                v0.put("user_level", this.b.b);
            }

            if (this.b.a != null) {
                v0.put("level", this.b.a);
            }

            this.a.a(this.z, "bonus", v0);
        }
    }

    void a(String arg4, int arg5, double arg6, int arg8) {
        this.a((((double) arg5)) * arg6, arg8);
        this.a(arg4, arg5, arg6);
    }

    void a(String arg8, int arg9, double arg10) {
        if (this.z == null) {
            by.e("UMGameAgent.init(Context) should be called before any game api");
        } else {
            HashMap v0 = new HashMap();
            v0.put("item", arg8);
            v0.put("amount", Integer.valueOf(arg9));
            v0.put("coin", Long.valueOf(((long) ((((double) arg9)) * arg10 * 100))));
            if (this.b.b != null) {
                v0.put("user_level", this.b.b);
            }

            if (this.b.a != null) {
                v0.put("level", this.b.a);
            }

            this.a.a(this.z, "buy", v0);
        }
    }

    void a(double arg7, String arg9, double arg10, int arg12, String arg13) {
        double v4 = 100;
        double v2 = 0;
        if (this.z == null) {
            by.e("UMGameAgent.init(Context) should be called before any game api");
            return;
        }

        if (arg7 >= v2 && arg10 >= v2) {
            HashMap v1 = new HashMap();
            if (!TextUtils.isEmpty(((CharSequence) arg9)) && arg9.length() > 0 && arg9.length() <= 3) {
                v1.put("curtype", arg9);
            }

            if (!TextUtils.isEmpty(((CharSequence) arg13))) {
                try {
                    int v0_1 = arg13.getBytes("UTF-8").length;
                    if (v0_1 <= 0) {
                    } else if (v0_1 > 1024) {
                    } else {
                        v1.put("orderid", arg13);
                    }
                } catch (UnsupportedEncodingException v0) {
                    v0.printStackTrace();
                }
            }
            v1.put("cash", Long.valueOf(((long) (arg7 * v4))));
            v1.put("coin", Long.valueOf(((long) (arg10 * v4))));
            v1.put("source", Integer.valueOf(arg12));
            if (this.b.b != null) {
                v1.put("user_level", this.b.b);
            }

            if (this.b.a != null) {
                v1.put("level", this.b.a);
            }

            this.a.a(this.z, "pay", v1);
        }
    }

    void a(Context arg3) {
        if (arg3 == null) {
            by.e("Context is null, can\'t init GameAgent");
        } else {
            this.z = arg3.getApplicationContext();
            this.a.a(((bx) this));
            this.b = new com.umeng.analytics.game.b(this.z);
            this.a.a(arg3, 1);
        }
    }

    void a(double arg8, double arg10, int arg12) {
        double v4 = 100;
        if (this.z == null) {
            by.e("UMGameAgent.init(Context) should be called before any game api");
        } else {
            HashMap v0 = new HashMap();
            v0.put("cash", Long.valueOf(((long) (arg8 * v4))));
            v0.put("coin", Long.valueOf(((long) (arg10 * v4))));
            v0.put("source", Integer.valueOf(arg12));
            if (this.b.b != null) {
                v0.put("user_level", this.b.b);
            }

            if (this.b.a != null) {
                v0.put("level", this.b.a);
            }

            this.a.a(this.z, "pay", v0);
        }
    }

    void a(double arg8, String arg10, int arg11, double arg12, int arg14) {
        this.a(arg8, arg12 * (((double) arg11)), arg14);
        this.a(arg10, arg11, arg12);
    }

    void a(String arg3) {
        this.b.b = arg3;
        SharedPreferences v0 = ba.a(this.z);
        if (v0 != null) {
            SharedPreferences.Editor v0_1 = v0.edit();
            v0_1.putString("userlevel", arg3);
            v0_1.commit();
        }
    }

    void a(boolean arg5) {
        by.b(String.format("Trace sleep time : %b", Boolean.valueOf(arg5)));
        com.umeng.analytics.game.a.a = arg5;
    }

    static com.umeng.analytics.game.b a(c arg1) {
        return arg1.b;
    }

    private void a(final String arg2, final int arg3) {
        if (this.z == null) {
            by.e("UMGameAgent.init(Context) should be called before any game api");
        } else {
            bz.a(new cb() {
                @Override
                public void a() {
                    com.umeng.analytics.game.b.a v0 = com.umeng.analytics.game.c.a(com.umeng.analytics.game.c.this).b(arg2);
                    if(v0 != null) {
                        long v0_1 = v0.e();
                        if(v0_1 <= 0) {
                            by.b("level duration is 0");
                        }
                        else {
                            HashMap v2 = new HashMap();
                            v2.put("level", arg2);
                            v2.put("status", Integer.valueOf(arg3));
                            v2.put("duration", Long.valueOf(v0_1));
                            if(com.umeng.analytics.game.c.a(com.umeng.analytics.game.c.this).b != null) {
                                v2.put("user_level", com.umeng.analytics.game.c.a(com.umeng.analytics.game.c.this).b);
                            }

                            com.umeng.analytics.game.c.c(com.umeng.analytics.game.c.this).a(com.umeng.analytics.game.c.b(com.umeng.analytics.game.c.this), "level", v2);
                        }
                    }
                    else {
                        by.d(String.format("finishLevel(or failLevel) called before startLevel"));
                    }
                }
            });
        }
    }

    public void a() {
        by.b("App resume from background");
        if (this.z == null) {
            by.e("UMGameAgent.init(Context) should be called before any game api");
        } else if (com.umeng.analytics.game.a.a) {
            this.b.b();
        }
    }

    void b(final String arg2) {
        if (this.z == null) {
            by.e("UMGameAgent.init(Context) should be called before any game api");
        } else {
            this.b.a = arg2;
            bz.a(new cb() {
                @Override
                public void a() {
                    com.umeng.analytics.game.c.a(com.umeng.analytics.game.c.this).a(arg2);
                    HashMap v0 = new HashMap();
                    v0.put("level", arg2);
                    v0.put("status", Integer.valueOf(0));
                    if(com.umeng.analytics.game.c.a(com.umeng.analytics.game.c.this).b != null) {
                        v0.put("user_level", com.umeng.analytics.game.c.a(com.umeng.analytics.game.c.this).b);
                    }

                    com.umeng.analytics.game.c.c(com.umeng.analytics.game.c.this).a(com.umeng.analytics.game.c.b(com.umeng.analytics.game.c.this), "level", v0);
                }
            });
        }
    }

    void b(String arg8, int arg9, double arg10) {
        if (this.z == null) {
            by.e("UMGameAgent.init(Context) should be called before any game api");
        } else {
            HashMap v0 = new HashMap();
            v0.put("item", arg8);
            v0.put("amount", Integer.valueOf(arg9));
            v0.put("coin", Long.valueOf(((long) ((((double) arg9)) * arg10 * 100))));
            if (this.b.b != null) {
                v0.put("user_level", this.b.b);
            }

            if (this.b.a != null) {
                v0.put("level", this.b.a);
            }

            this.a.a(this.z, "use", v0);
        }
    }

    static Context b(c arg1) {
        return arg1.z;
    }

    public void b() {
        if (this.z == null) {
            by.e("UMGameAgent.init(Context) should be called before any game api");
        } else if (com.umeng.analytics.game.a.a) {
            this.b.a();
        }
    }

    void c(String arg2) {
        if (this.z == null) {
            by.e("UMGameAgent.init(Context) should be called before any game api");
        } else {
            this.a(arg2, 1);
        }
    }

    static b c(c arg1) {
        return arg1.a;
    }

    void d(String arg2) {
        if (this.z == null) {
            by.e("UMGameAgent.init(Context) should be called before any game api");
        } else {
            this.a(arg2, -1);
        }
    }
}

